# Build recipe for pcc
#
# Copyright 2016,2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=pcc
version=$(date +%Y%m%d)
release=1

description="
The pcc compiler is based on the original Portable C Compiler by
S. C. Johnson, written in the late 70's. About 50% of the frontend
code and 80% of the backend code has been modified.The compiler is
based on the original Portable C Compiler by S. C. Johnson, written in
the late 70's. About 50% of the frontend code and 80% of the backend
code has been modified.

The project goal is to write a C99 compiler while still keeping it
small, simple, fast and understandable. PCC is not affiliated with any
other project, but the compiler has been imported into the OpenBSD and
NetBSD base systems.
"

homepage=http://pcc.ludd.ltu.se/
license=BSD

tarname=${program}-${version}.tgz

# Remote source(s)
fetch=http://pcc.ludd.ltu.se/ftp/pub/pcc/$tarname

build() {
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS"\
    $configure_args \
    --libdir=/usr/lib${libSuffix} \
    --mandir=$mandir \
    --docdir=$docdir \
    --enable-tls \
    --build="$(cc -dumpmachine)"

    make -j${jobs}
    make -j${jobs} install DESTDIR="$destdir"

    # Compress and link man pages (if needed)
    if [ -d "${destdir}/$mandir" ] ; then
	(
            cd "${destdir}/$mandir"
	    find . -type f -exec lzip -9 '{}' +
	    find . -type l | while read -r file
	    do
		ln -sf "$(readlink -- "$file").lz" "${file}.lz"
		rm -- "$file"
	    done
	)
    fi
}
